package com.suming.springboot_game.controller;

import com.suming.springboot_game.common.Result;
import com.suming.springboot_game.entity.Construct;
import com.suming.springboot_game.entity.Role;
import com.suming.springboot_game.service.ConstructService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/construct")
public class ConstructController {
    @Autowired
    private ConstructService constructService;

    @GetMapping("/page")
    public Result page(@RequestParam Integer pageNum,
                       @RequestParam Integer pageSize,
                       @RequestParam(defaultValue = "") String name){
        pageNum = (pageNum - 1) * pageSize;
        Map<String,Object> res = new HashMap<>();
        List<Construct> data = constructService.selectPage(pageNum,pageSize,name);
        Integer total = constructService.countByName(name);
        res.put("data",data);
        res.put("total",total);
        return Result.success(res);
    }

    @PostMapping("/jianzao")
    public Result jianzao(@RequestBody Construct construct){
        return Result.success(constructService.jianzao(construct));
    }

    @PostMapping("/destroy")
    public Result destroy(@RequestBody List<Integer> ids){
        return Result.success(constructService.destroy(ids));
    }

}
